﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for DALQuyen
/// </summary>
public class DALQuyen:StandardConnectDB,IQuyen
{
	public DALQuyen()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Quyen GetQuyenById(int idRole)
    {
        Quyen role = new Quyen();

        //Create param list store parameter execute store procedure
        Dictionary<String, Object> paramList = new Dictionary<String, Object>();
        //Add param pIdRole to paramList
        paramList.Add("@pRoleId", idRole);

        //Get Role from database by store procedure
        DataTable dtRoles = this.DTExecuteSelect("spGetRoleById", paramList);

        //Create object DataRow store data first's row in DataTable
        DataRow dr = dtRoles.Rows[0];

        //Convert object DataRow to object Roles
        role = this.ConvertObjectDataRowToQuyen(dr);

        return role;
    }





    public Quyen ConvertObjectDataRowToQuyen(System.Data.DataRow dr)
    {
        Quyen role = new Quyen();
        role.MaQuyen = int.Parse(dr["MAQUYEN"].ToString());
        role.Tenquyen = dr["TENQUYEN"].ToString();
       
        return role;
    }

    public DataTable getAllQuyen()
    {
        string sql="SELECT MAQUYEN,TENQUYEN FROM QUYEN";
        return this.DTExecuteSelect(sql);
    }
}